<?php
namespace app\controller;

use think\Request;
use app\controller\Base;
use app\common\UtilService;
use app\model\EaWxPlatform;

class Platform extends Base
{
    /**
     * [index 首页]
     * @since  2025-06-04
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function index(Request $request)
    {
    	$param = UtilService::getMore([
    		['page', 1],
    		['pageSize', 24],
    		['type', '']
    	]);

    	$arrs = [];

        # 公众号分类
        $arrs['pla_type'] = EaWxPlatform::plaGroupName();

        $arrs['list'] = EaWxPlatform::getPlatformList($param);

        # 异步获取列表
        if ($request->isAjax()) {

        	$param = UtilService::getMore([
	    		['page', 1],
	    		['pageSize', 24],
	    		['type', '']
	    	]);

        	$list = EaWxPlatform::getPlatformList($param);

        	return success($list, '获取成功');

        }

        return view('index', compact('arrs', 'param'));
    }

    /**
     * [info 详细]
     * @since  2025-06-04
     * @author Dai哥
     * @param  Request    $request [description]
     * @return [type]              [description]
     */
    public function info(Request $request)
    {
    	$param = UtilService::getMore([
    		['id', ''],
    	]);

    	# 公众号分类
        $arrs['pla_type'] = EaWxPlatform::plaGroupName();

        $arrs['info'] = EaWxPlatform::getPlatformInfo($param)->toArray();

        # 热度最高6条
        $arrs['hot'] = EaWxPlatform::where('status', 1)->where('id', '<>', $param['id'])->order('views DESC')->limit(5)->cache(120)->select();

        # 下一个 5
        $xia = EaWxPlatform::field('id, name')->where('id', '>', $param['id'])->order('id ASC')->limit(1)->cache(120)->find();

        # 上一个 5
        $shang = EaWxPlatform::field('id, name')->where('id', '<', $param['id'])->order('id DESC')->limit(1)->cache(120)->find();

        return view('info', compact('arrs', 'xia', 'shang'));
    }
}
